-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support app command contexts #9406
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR.
Just some minor bikeshedding/comments for the first pass:
AppCommandContext
is not an enum, it's actually a flag type. Discord has recently been doing bitfields using an array because they falsely believe it leads to better developer experience since they are targeting developers that do not know how to bitshift. I suggest migrating this over to use the newArrayFlags
type and work with it. I have tried to get them to change this to a regular integer but they seem to want to not want to change it to the more space-efficient and sane format.allowed_contexts
and any external reference tocontext
in this well context should probably be calledrestrict
instead. The type should still be calledAppCommandContext
but the attribute (and maybe eventual decorator) should be calledrestrict
.private_only
should probably be renamed toprivate_channel_only
for consistency with the library (e.g.abc.PrivateChannel
).- The flag names for
AppCommandContext
should not use the Discord naming scheme since they are bad, instead it should probably beguild
,dm_channel
, andprivate_channel
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're missing the documentation for the new decorators. They need to be added to the API reference. Other than that this PR looks good.
@@ -2430,6 +2473,135 @@ def inner(f: T) -> T: | |||
return inner(func) | |||
|
|||
|
|||
def private_channel_only(func: Optional[T] = None) -> Union[T, Callable[[T], T]]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should either drop the ability to optionally use parens or add the necessary overloads here otherwise you'll get type errors.
.. code-block:: python3 | ||
|
||
@app_commands.command() | ||
@app_commands.allow_contexts(guilds=False, dms=False, private_channels=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@app_commands.allow_contexts(guilds=False, dms=False, private_channels=True) | |
@app_commands.allow_contexts(guilds=True, dms=False, private_channels=True) |
Didn't you want to set guilds to True in the example as that's what you say in the response message just below
Superseded by #9760 |
Summary
Adds
@dm_only
and@private_only
decorators to allow specifying the newcontexts
field in app commands, as specified here, as well as the relevant init args.The docs mention that if this field is specified, the permission calculation ignores the
dm_permission
field. Not sure how this should be reflected in the library for backwards compatibility purposes.Checklist